/*
 * Copyright (c) 2017-2018 PlayerOne.
 *
 * The MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.eostoken.eos_wallet.db;

import android.annotation.SuppressLint;
import android.os.Parcel;
import android.os.Parcelable;

import org.greenrobot.greendao.annotation.Convert;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.NotNull;
import org.greenrobot.greendao.annotation.Unique;

import java.util.Collections;
import java.util.List;

import org.greenrobot.greendao.annotation.Generated;

/**
 * Created by swapnibble on 2017-09-25.
 */
@SuppressLint("ParcelCreator")
@Entity
public class MgpWallet implements Parcelable {
    @Id(autoincrement = true)
    private Long id;
    @Convert(columnType = String.class, converter = StringConverter.class)
    public List<String> accountNameList;
    @NotNull
    private String walletPassword;
    @Unique
    private String currentAccountName;
    @NotNull
    private String privateKey;
    private String publicKey;
    @NotNull
    public boolean locked;
    private String walletName;

    @Convert(columnType = String.class, converter = StringConverter.class)
    List<String> mnemonicCode;

    private String hint;

    protected MgpWallet(Parcel in) {
        if (in.readByte() == 0) {
            id = null;
        } else {
            id = in.readLong();
        }
        accountNameList = in.createStringArrayList();
        walletPassword = in.readString();
        currentAccountName = in.readString();
        privateKey = in.readString();
        publicKey = in.readString();
        locked = in.readByte() != 0;
        mnemonicCode = in.createStringArrayList();
        hint = in.readString();
        walletName = in.readString();
    }

    @Generated(hash = 832545134)
    public MgpWallet(Long id, List<String> accountNameList,
            @NotNull String walletPassword, String currentAccountName,
            @NotNull String privateKey, String publicKey, boolean locked,
            String walletName, List<String> mnemonicCode, String hint) {
        this.id = id;
        this.accountNameList = accountNameList;
        this.walletPassword = walletPassword;
        this.currentAccountName = currentAccountName;
        this.privateKey = privateKey;
        this.publicKey = publicKey;
        this.locked = locked;
        this.walletName = walletName;
        this.mnemonicCode = mnemonicCode;
        this.hint = hint;
    }

    @Generated(hash = 890695170)
    public MgpWallet() {
    }



    public static final Creator<MgpWallet> CREATOR = new Creator<MgpWallet>() {
        @Override
        public MgpWallet createFromParcel(Parcel in) {
            return new MgpWallet(in);
        }

        @Override
        public MgpWallet[] newArray(int size) {
            return new MgpWallet[size];
        }
    };

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<String> getAccountNameList() {
        return accountNameList;
    }

    public void setAccountNameList(List<String> accountNameList) {
        this.accountNameList = accountNameList;
    }

    public String getCurrentAccountName() {
        return currentAccountName;
    }

    public void setCurrentAccountName(String currentAccountName) {
        this.currentAccountName = currentAccountName;
    }

    public String getWalletPassword() {
        return walletPassword;
    }

    public void setWalletPassword(String walletPassword) {
        this.walletPassword = walletPassword;
    }

    public String getPrivateKey() {
        return privateKey;
    }

    public void setPrivateKey(String privateKey) {
        this.privateKey = privateKey;
    }

    public String getPublicKey() {
        return publicKey;
    }

    public void setPublicKey(String publicKey) {
        this.publicKey = publicKey;
    }

    public boolean isLocked() {
        return locked;
    }

    public void setLocked(boolean locked) {
        this.locked = locked;
    }

    public List<String> getMnemonicCode() {
        return mnemonicCode;
    }

    public void setMnemonicCode(List<String> mnemonicCode) {
        this.mnemonicCode = mnemonicCode;
    }

    public boolean getLocked() {
        return this.locked;
    }

    public String getHint() {
        return hint;
    }

    public void setHint(String hint) {
        this.hint = hint;
    }

    public String getWalletName() {
        return walletName;
    }

    public void setWalletName(String walletName) {
        this.walletName = walletName;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (id == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(id);
        }
        dest.writeStringList(accountNameList);
        dest.writeString(walletPassword);
        dest.writeString(currentAccountName);
        dest.writeString(privateKey);
        dest.writeString(publicKey);
        dest.writeByte((byte) (locked ? 1 : 0));
        dest.writeStringList(mnemonicCode);
        dest.writeString(hint);
        dest.writeString(walletName);
    }
}
